home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Scene Storm
/
Scene Storm - Volume 1.iso
/
coding
/
c
/
northc
/
example2.lzh
/
make
/
make.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-30
|
3KB
|
154 lines
/*
(c) 1990 S.Hawtin.
Permission is granted to copy this file provided that:
1) It is not used for commercial gain
2) This notice is included in all copies
3) Altered copies are marked as such.
No liability is accepted for the contents of the file.
make.c within WBmake
*/
/* Make program to call from WB */
#include <stdio.h>
#include "make.h"
extern FileInfo *read_makefile();
FileInfo *root;
/* In built funtions, like depend etc */
void
do_depend()
{/* Search for all the dependencies */
printf("Make cannot yet do depends\n");
}
void
do_blink()
{/* Create a <tool>.blink file */
FILE *b_file;
ConsCell *dep_obj;
char b_name[32];
sprintf(b_name,"%s.blink",root->name);
b_file = fopen(b_name,"w");
fprintf(b_file,"FROM\n clibs:crt0.o\n");
dep_obj = root->depends;
while(dep_obj)
{if(dep_obj->car->type == 'o')
fprintf(b_file," %s\n",dep_obj->car->name);
dep_obj = dep_obj->cdr;
}
fprintf(b_file,"TO\n %s\nLIB\n clibs:libc.a\n",root->name);
fclose(b_file);
}
void
do_all()
{do_depend();
do_blink();
}
typedef void (*VoidFun)();
#define INBUILT_MAX 2
VoidFun inbuilt_funs[INBUILT_MAX] =
{do_depend,do_blink
};
char *inbuilt_names[INBUILT_MAX] =
{"$*.depend","$*.blink"};
int
inbuilt_index(str)
char *str;
{int i;
for(i=0;i<INBUILT_MAX;i++)
if(strcmp(inbuilt_names[i],str) == 0)
return(i);
return(-1);
}
/* Variables set by command options */
char makefile[20] = "Makefile";
char target[32] = "";
int just_test = 0;
doopts(argc,argv)
int argc;
char **argv;
{/* Step through the options setting the values */
int i;
for(i=1;i<argc;i++)
{/* All switches muststart with '-' */
if(*argv[i]=='-')
{
/* Single switches only */
switch(argv[i][1])
{case 'f': case 'F':
strcpy(makefile,&argv[i][2]);
break;
case '?':
just_test = -1;
break;
default:
printf("Unknown switch %c\n",argv[i][1]);
printf("WBmake [-f<makefile>] [target]\n");
exit(10);
}
}
else
{/* Must be the target name, and last option */
strcpy(target,argv[i]);
return;
}
}
}
main(argc,argv)
int argc;
char **argv;
{/* Make the object */
FILE *temp;
char *temp_file;
char sys_cmnd[32];
int inbuilt;
doopts(argc,argv);
/* Now read the Makefile */
inbuilt = inbuilt_index(target);
if(inbuilt==-1)
{root = read_makefile(makefile,target);
if(root==NULL)
{printf("Cannot find rules for \"%s\"\n",target);
exit(10);
}
/* Hack to get arround the system return bug */
temp_file = tmpnam(NULL);
temp = fopen(temp_file,"w");
go_make(root,temp);
fclose(temp);
sprintf(sys_cmnd,"execute %s",temp_file);
system(sys_cmnd);
remove(temp_file);
}
else
{/* One of the inbuilt functions */
root = read_makefile(makefile,"");
if(root==NULL)
{printf("Cannot find object to make\n",target);
exit(10);
}
(*inbuilt_funs[inbuilt])();
}
}